package top.cluski.shardingsphere;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import top.cluski.shardingsphere.entity.Course;
import top.cluski.shardingsphere.mapper.CourseMapper;

import javax.annotation.Resource;

/**
 * 分库分表之后的测试
 */
@SpringBootTest
public class ShardingJDBCTest02 {

    @Resource
    CourseMapper courseMapper;

    @Test
    public void queryByIn() {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("cid", 684449647967604737L, 684449648030519297L, 1231215L);
        courseMapper.selectList(queryWrapper).forEach(course -> {
            System.out.println(course);
        });

    }

    @Test
    public void  queryCourseByBetween() {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("cid", 684449647938244608L, 684449648030519297L);
        courseMapper.selectList(queryWrapper).forEach(course -> {
            System.out.println(course);
        });
    }

    /**
     * 只要可以查询到结果，就可以进行orderby等聚合操作
     */
    @Test
    public void  queryCourseOrder() {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByDesc("cid");
        queryWrapper.orderByDesc("user_id");
        courseMapper.selectList(queryWrapper).forEach(course -> {
            System.out.println(course);
        });
    }

    /**
     * 也可以使用一些聚合函数，例如MAX()等
     */
    @Test
    public void  queryCourseMax() {
        String course = courseMapper.selectMax();
        System.out.println(course);
    }
}
